package 集合;
//排序
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class Test1 {
	public static void main(String [] args) throws Exception
	{
		PrintStream ps=new PrintStream(new FileOutputStream("D:\\代码\\firstDemo\\src\\firstDemo\\example"));
		List<Student> stu=new ArrayList<>();
		stu.add(new Student("张三",001,3,66));
		stu.add(new Student("李四",003,3,88));
		stu.add(new Student("王五",005,3,99));
		stu.add(new Student("范闲",002,3,77));
		stu.add(new Student("李平",004,3,33));
		System.out.println(stu);
		for(Student s:stu)
		{
			System.out.println(s);
		}
		System.out.println("---------------------------");//控制台
//		Collections.sort(stu,new Comparator<Student>()
//				{
//
//					@Override
//					public int compare(Student o1, Student o2) {
//						// TODO Auto-generated method stub
//						return o1.getId()-o2.getId();
//					}
//						
//				});
		//lambda表达式
		Collections.sort(stu,(o1,o2)->o2.getId()-o1.getId());
		//Collections.sort(stu);//默认排序
		ps.println(stu);//向文件中打印任意类型的数据
		//将打印目标换成文件
		System.setOut(ps);//将输出位置改为文件中
		for(Student s:stu)
		{
			System.out.println(s);
		}
		ps.close();
	}
}